<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageName}.mapper.${entity}Mapper">
	
	<resultMap id="BaseResultMap"  type="${packageName}.model.${entity}" >
		<#list fieldList as var>
		 <result column="${var[0]}" property="${var[2]}"/>
		</#list>
	</resultMap>
	
	<!--表名 -->
	<sql id="TableName">
		${tableName}
	</sql>
	
	<!-- 字段 -->
	<sql id="Field">
	<#list fieldList as var>
		${var[0]},	
	</#list>
	</sql>
	
	<!-- 字段值 -->
	<sql id="FieldValue">
	<#list fieldList as var>
		${r"#{"}${var[0]}${r"}"},	
	</#list>
	</sql>
	
	<!-- 新增-->
	<insert id="insert" parameterType="${packageName}.model.${entity}">
		insert into 
	<include refid="TableName"></include>
		(
	<include refid="Field"></include>
		) values (
	<include refid="FieldValue"></include>
		)
	</insert>
	
	<!-- 删除-->
	<delete id="delete" parameterType="java.lang.String">
		delete from
		<include refid="TableName"></include>
		where 
			id = ${r"#{"}id${r"}"}
	</delete>
	
	<!-- 修改 -->
	<update id="update" parameterType="${packageName}.model.${entity}">
		update
		<include refid="TableName"></include>
		<set>
		<#list fieldList as var>
			<if test="${var[2]} != null">${var[0]}=${r"#{"}${var[2}${r"}"},</if>
	    </#list>
		</set>
		where 
			id = ${r"#{"}id${r"}"}
	</update>
	
	<!-- 通过ID获取数据 -->
	<select id="queryById" parameterType="java.lang.String" resultMap="BaseResultMap">
		select 
			<include refid="Field"/>
		from 
		<include refid="TableName"/>
		where 
			id = ${r"#{"}id${r"}"}
	</select>
	
	<!-- 列表 -->
	<select id="list" parameterType="${packageName}.dto.${entity}Dto" resultMap="BaseResultMap">
		select
		<include refid="Field"/>
		from 
		<include refid="TableName"/> 
		where 1=1
		<if test="pageSize != null">
			limit  ${r"#{"}pageSize${r"}"} 
		</if>
		<if test="dataLimitStart != null">
			offset  ${r"#{"}dataLimitStart${r"}"}  
		</if>
	</select>
	
	<!--查询数量-->
	<select id="count" parameterType="${packageName}.dto.${entity}Dto" resultType="Integer">

		select count(1) from <include refid="TableName"/> 

	</select>
</mapper>